﻿using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour {

    ObjectPool bulletPool;
    public GameObject bulletObject;
    public Player player;
    public int BulletPoolSize = 50;

	// Use this for initialization
	void Start () {
        if (bulletObject != null)
        {
            bulletPool = new ObjectPool(BulletPoolSize, false);
            bulletPool.Create(bulletObject);
        }

        if (player != null)
            player.OnFireHandler += OnFireEvent;
	}
	
    void OnFireEvent()
    {
        if (bulletPool != null)
        {
            GameObject bullet = bulletPool.Spawn(bulletObject);

            if (bullet != null)
            {
                bullet.transform.position = new Vector3(player.transform.position.x, player.transform.position.y, 0);
                bullet.transform.rotation = player.transform.rotation;
            }
        }
    }

	// Update is called once per frame
	void Update () {
	
	}
}
